//
//  SelectCardViewController.m
//  YTwallet
//
//  Created by ZhangLin on 2019/3/28.
//  Copyright © 2019年 hadrlog. All rights reserved.
//

#import "SelectCardViewController.h"
#import "SelectCardView.h"
#import "VerifyCardViewController.h"
#import "SelectCardTableViewCell.h"
//获取开户银行
#import "BankListModelPack.h"
//银行列表View
#import "BankListView.h"
//付款卡View
#import "SelectPayCardDetailView.h"
//付款卡自定义cell
#import "SelectPayCardDetailTableViewCell.h"

#import "SelectCreditCardModelPack.h"

#import "SelectCardTabFooterView.h"

//获取费率模型
#import "SelectCardModelPack.h"
//提交订单模型
#import "CreateNewOrderModelPack.h"
//H5交易页面
#import "H5TradeViewController.h"

//添加银行卡页面
#import "AddCreditCardViewController.h"

#import <UIImageView+WebCache.h>

@interface SelectCardViewController ()<UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate>
@property(nonatomic,strong)SelectCardView *sv;

@property(nonatomic,strong)UIButton *nextStypeBtn;

@property(nonatomic,strong)NSMutableArray *titleArray;

//银行列表数组
@property(nonatomic,strong)NSMutableArray *bankNameArray;
//弹出付款卡
@property(nonatomic,strong)SelectPayCardDetailView *selectPayCardDetailView;


//银行卡号输入框
@property(nonatomic,strong)UITextField *bankNumTf;
//开户银行输入框
@property(nonatomic,strong)UITextField *bankNameTF;
//CVN2输入框
@property(nonatomic,strong)UITextField *bankCVN2Tf;
//有效期输入框
@property(nonatomic,strong)UITextField *bankvalidityTf;
//预留手机号输入框
@property(nonatomic,strong)UITextField *bankreservedTf;

//记录选择银行卡的indexPath
@property(nonatomic,strong)NSIndexPath *indexPath;


//付款卡列表数组
@property(nonatomic,strong)NSMutableArray *cardModelArray;

//银行卡ID
@property(nonatomic,strong)NSString *bankId;//对应后端的id
//银行卡简称
@property(nonatomic,strong)NSString *bankCode;//对应后端的bankid

@end

@implementation SelectCardViewController


-(NSMutableArray *)cardModelArray
{
    if (_cardModelArray == nil) {
        _cardModelArray = [NSMutableArray array];
    }
    return _cardModelArray;
}

-(NSMutableArray *)titleArray
{
    if (_titleArray == nil) {
        _titleArray = [NSMutableArray array];
    }
    return _titleArray;
}

-(NSMutableArray *)bankNameArray
{
    if (_bankNameArray == nil) {
        _bankNameArray = [NSMutableArray array];
    }
    return _bankNameArray;
}

-(void)loadView
{
    [super loadView];
    
    self.sv = [[SelectCardView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview: self.sv];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.sv.nameLab.text = [AppTools shareInstance].userInfo.userName;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.sv.bottomView.hidden = YES;
    self.sv.rateAndtimeView.hidden = YES;
    
    self.title = @"选择付款卡";
    self.view.backgroundColor = ETColorWithRGB(242, 244, 246);
    self.sv.moneyNumLab.text = [NSString stringWithFormat:@"￥%@",self.moneyStr];
    //下一步
    [self createNextStype];
    //创建tableView
    [self createTableView];
    //选择付款卡事件
    [self.sv.selectcardBtn addTarget:self action:@selector(selectcardBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
    
    [self.sv.arrowBtn addTarget:self action:@selector(selectcardBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
}

-(void)selectcardBtnAction
{
    //防止多次点击
    self.sv.selectcardBtn.userInteractionEnabled = NO;
    self.nextStypeBtn.userInteractionEnabled = NO;
    NSLog(@"点击选择付款卡");
    //查询付款卡列表
    [self getCredictCardList];
}

-(void)getCredictCardList
{
    NSString *url = [[ServerAddressModel shareInstance] fullTAnd0AddrWithParameter:@"/epay_apps/creditCard/showCreditCards"];
    [[ETONEHttpClient sharedInstance] doHTTPSPOST:url Parameters:nil HttpBody:nil SuccessHandler:^(id responseObject) {
        
        NSDictionary *dic = [responseObject mj_JSONObject];
        NSString *code = dic[@"code"];
        if ([@"0000" isEqualToString:code]) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                [self dealCredictCardList:responseObject];
            });
            
        }
        
    } FailedHandler:^(NSError *error) {
        
        self.sv.selectcardBtn.userInteractionEnabled = YES;
        self.nextStypeBtn.userInteractionEnabled = YES;
        
    }];
    
}
-(void)dealCredictCardList:(id)responseObject
{
    
    //清空模型数组
    [self.cardModelArray removeAllObjects];
    
    
    [self popCardList];
    self.selectPayCardDetailView.payCardTableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ETScreenW, 0.0001f)];
    self.selectPayCardDetailView.payCardTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ETScreenW, 0.0001f)];
    SelectCreditCardResponse *selectResponse = [SelectCreditCardResponse mj_objectWithKeyValues:responseObject];
    for (SelectCreditCardRecord *record in selectResponse.response.cardList) {
        [self.cardModelArray addObject:record];
    }
    [self.selectPayCardDetailView.payCardTableView reloadData];
}

-(void)popNoneView
{
    self.selectPayCardDetailView = [[SelectPayCardDetailView alloc] initWithFrame:(CGRectMake(0, ETScreenH, ETScreenW, 400))];
    AppDelegate *delegate  = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [delegate.window addSubview:self.selectPayCardDetailView];
    
    //退出按钮
    [self.selectPayCardDetailView.delBtn addTarget:self action:@selector(delBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    //给弹出框加上点击事件  响应底部弹窗消失
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SelectPayCardtapGesturedDetected:)];
    tapGesture.delegate = self;
    [self.selectPayCardDetailView addGestureRecognizer:tapGesture];
    
    
    
    
    __weak SelectCardViewController *weakSelf = self;
    self.selectPayCardDetailView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
    [UIView animateWithDuration:0.5 animations:^{
        [weakSelf.selectPayCardDetailView setFrame:CGRectMake(0, 0, ETScreenW, ETScreenH)];
    } completion:^(BOOL finished) {
        weakSelf.selectPayCardDetailView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
    }];
    
    
    
    
}


-(void)popCardList
{
    self.selectPayCardDetailView = [[SelectPayCardDetailView alloc] initWithFrame:(CGRectMake(0, ETScreenH, ETScreenW, 400))];
    AppDelegate *delegate  = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [delegate.window addSubview:self.selectPayCardDetailView];
    
    //退出按钮
    [self.selectPayCardDetailView.delBtn addTarget:self action:@selector(delBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    //给弹出框加上点击事件  响应底部弹窗消失
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SelectPayCardtapGesturedDetected:)];
    tapGesture.delegate = self;
    [self.selectPayCardDetailView addGestureRecognizer:tapGesture];
    
    __weak SelectCardViewController *weakSelf = self;
    self.selectPayCardDetailView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
    [UIView animateWithDuration:0.5 animations:^{
        [weakSelf.selectPayCardDetailView setFrame:CGRectMake(0, 0, ETScreenW, ETScreenH)];
    } completion:^(BOOL finished) {
        weakSelf.selectPayCardDetailView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
        self.sv.selectcardBtn.userInteractionEnabled = YES;
        self.nextStypeBtn.userInteractionEnabled = YES;
    }];
    

    self.selectPayCardDetailView.payCardTableView.delegate = self;
    self.selectPayCardDetailView.payCardTableView.dataSource = self;
    self.selectPayCardDetailView.payCardTableView.separatorStyle = UITableViewCellSelectionStyleNone;
    self.selectPayCardDetailView.payCardTableView.userInteractionEnabled = YES;
    [self.selectPayCardDetailView.payCardTableView registerClass:[SelectPayCardDetailTableViewCell class] forCellReuseIdentifier:@"SelectPayCardDetailCell"];
    
}

-(void)delBtnAction
{
    [self PayDetailCardViewdismiss];
}



-(void)createTableView
{
    self.titleArray = @[@"银行卡号",@"开户银行",@"CVN2",@"有效期",@"预留手机号",].mutableCopy;
    
    
    self.sv.tableView.delegate = self;
    self.sv.tableView.dataSource = self;
    self.sv.tableView.layer.cornerRadius = 5;
    self.sv.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    self.sv.tableView.scrollEnabled = NO;
    self.sv.tableView.userInteractionEnabled = NO;
    [self.sv.tableView registerClass:[SelectCardTableViewCell class] forCellReuseIdentifier:@"cell"];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.sv.tableView) {
        return 5;
    }else
    {
        return self.cardModelArray.count;
    }
    
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.sv.tableView) {                  //最底层显示TableView
        SelectCardTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.titleLab.text = self.titleArray[indexPath.row];
        //赋值输入框
        if (indexPath.row == 0) {
            self.bankNumTf = cell.titleTf;
        }
        if (indexPath.row == 1) {
            self.bankNameTF = cell.titleTf;
        }
        if (indexPath.row == 2) {
            self.bankCVN2Tf = cell.titleTf;
            self.bankCVN2Tf.keyboardType = UIKeyboardTypeNumberPad;
        }
        if (indexPath.row == 3) {
            self.bankvalidityTf = cell.titleTf;
            self.bankvalidityTf.keyboardType = UIKeyboardTypeNumberPad;
        }
        if (indexPath.row == 4) {
            self.bankreservedTf = cell.titleTf;
            self.bankreservedTf.keyboardType = UIKeyboardTypeNumberPad;
        }
        
        //最后一个cell不显示分割线
        if (indexPath.row == 4) {
            cell.lineView.hidden = YES;
        }else
        {
            cell.lineView.hidden = NO;
        }
        
        return cell;
    }else                                                       //选择付款卡TableView
    {
        SelectPayCardDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SelectPayCardDetailCell" forIndexPath:indexPath];
        SelectCreditCardRecord *record = self.cardModelArray[indexPath.row];
        cell.banNameLab.text = record.bankName;
        //银行卡小图标
        if (record.bankId.length == 0) {
            cell.bankImv.image = [UIImage imageNamed:@"logo_yinhang"];
        }else
        {           
            [cell.bankImv sd_setImageWithURL:[NSURL URLWithString:record.bankIcon] placeholderImage:[UIImage imageNamed:@"logo_yinhang"]];
        }
        
//        cell.tailNumberLab.attributedText = [self changeTailNumStr:record.cardNo];
        cell.tailNumberLab.text = [NSString stringWithFormat:@"尾号(%@)",record.cardNo];
        
        
        
        
        if (self.indexPath && indexPath == self.indexPath) {
            cell.arrowImv.hidden = NO;
        }else
        {
            cell.arrowImv.hidden = YES;
        }
        
        
        //最后一个cell不显示分割线
        if (indexPath.row == 4) {
            cell.lineView.hidden = YES;
        }else
        {
            cell.lineView.hidden = NO;
        }
        return cell;
    }
    
}

//取银行名字第一个字
-(NSString *)changeBankNameStr:(NSString *)bankNameStr
{
    if (bankNameStr.length > 1) {
        NSString *string = [bankNameStr substringWithRange:NSMakeRange(0, 1)];
        return string;
    }else
    {
        return bankNameStr;
    }
}
//处理尾号
-(NSMutableAttributedString *)changeTailNumStr:(NSString *)bankNum
{
    if (bankNum.length == 4) {
        NSString *tailNumStr = [NSString stringWithFormat:@"尾号(%@)",bankNum];
        NSMutableAttributedString *attTailNum = [[NSMutableAttributedString alloc] initWithString:tailNumStr];
        
        
        [attTailNum addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, 8)];
        
        [attTailNum addAttribute:NSForegroundColorAttributeName value:ETColorWithRGB(153, 153, 153) range:NSMakeRange(0, 2)];
        [attTailNum addAttribute:NSForegroundColorAttributeName value:ETColorWithRGB(51, 51, 51) range:NSMakeRange(2, 5)];
        
        return attTailNum;
    }else if(bankNum.length > 4)
    {
        bankNum = [bankNum substringWithRange:(NSMakeRange(bankNum.length - 4, 4))];
        NSString *tailNumStr = [NSString stringWithFormat:@"尾号(%@)",bankNum];
        NSMutableAttributedString *attTailNum = [[NSMutableAttributedString alloc] initWithString:tailNumStr];
        
        
        [attTailNum addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, 8)];
        
        [attTailNum addAttribute:NSForegroundColorAttributeName value:ETColorWithRGB(153, 153, 153) range:NSMakeRange(0, 2)];
        [attTailNum addAttribute:NSForegroundColorAttributeName value:ETColorWithRGB(51, 51, 51) range:NSMakeRange(2, 5)];
        
        return attTailNum;
        
    }else
    {
        return [[NSMutableAttributedString alloc] initWithString:bankNum];
    }
    
    
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.sv.tableView) {         //最底层显示tableView

    }else
    {
        NSLog(@"点击付款卡选择Cell");
        self.indexPath = indexPath;
        [self.selectPayCardDetailView.payCardTableView reloadData];
        //退出收款卡列表
        [self PayDetailCardViewdismiss];
        //Net赋值到页面
        SelectCreditCardRecord *record = self.cardModelArray[indexPath.row];
        self.bankId = record.ID;//提交订单页面赋值ID
        self.bankCode = record.bankId;
        
        [self getRateAndArriveTimeWith:record.ID banName:record.bankName leftPhone:record.leftPhone cardNum:record.cardNo];
       
    }
}
-(void)getRateAndArriveTimeWith:(NSString *)bankId banName:(NSString *)bankName leftPhone:(NSString *)leftPhone cardNum:(NSString *)cardNum
{
    
    SelectcardRequest *request = [[SelectcardRequest alloc] init];
    request.transAmount = self.moneyStr;
    request.Id = bankId;
    request.payId = @"3";
    NSDictionary *dic = [request mj_keyValues];
    NSString *url = [[ServerAddressModel shareInstance] fullTAnd0AddrWithParameter:@"/epay_apps/payNew/getratebypayB0400"];
    [[ETONEHttpClient sharedInstance] doHTTPSPOST:url Parameters:dic HttpBody:nil SuccessHandler:^(id responseObject) {
        
        NSDictionary *dic = [responseObject mj_JSONObject];
        NSString *code = dic[@"code"];
        if ([@"0000" isEqualToString:code]) {
            [self dealSelectCardWith:responseObject banName:bankName leftPhone:leftPhone cardNum:cardNum];
        }
        
    } FailedHandler:^(NSError *error) {
        
    }];
}

-(void)dealSelectCardWith:(id)responseObject banName:(NSString *)bankName leftPhone:(NSString *)leftPhone cardNum:(NSString *)cardNum
{
    
    self.sv.bottomView.hidden = NO;
    self.sv.rateAndtimeView.hidden = NO;
    [self.sv.selectcardBtn setTitle:@"更改付款卡" forState:(UIControlStateNormal)];
    self.bankNumTf.attributedText = [self changeTailNumStr:cardNum];
    self.bankNameTF.text = bankName;
    self.bankCVN2Tf.text = @"***";
    self.bankvalidityTf.text = @"****";
    self.bankreservedTf.text = leftPhone;
    
    
    SelectcardResponse *selectCardResponse = [SelectcardResponse mj_objectWithKeyValues:responseObject];
    self.sv.rateValueLab.text = [self dealRateWithRate:selectCardResponse.response.rate maxRate:selectCardResponse.response.maxRate];
    self.sv.arriveValueLab.text = [self dealTimeWithTranbeginTime:selectCardResponse.response.tranbeginTime tranendTime:selectCardResponse.response.tranendTime];
}
//处理费率
-(NSString *)dealRateWithRate:(NSString *)rateStr maxRate:(NSString *)maxRateStr
{
    NSString *str = [NSString stringWithFormat:@"%@%@+%@元/笔",rateStr,@"%",maxRateStr];
    return str;
}

//处理秒到时间
-(NSString *)dealTimeWithTranbeginTime:(NSString *)tranbeginTime tranendTime:(NSString *)tranendTime
{
    NSString *str = [NSString stringWithFormat:@"每天%@-%@",tranbeginTime,tranendTime];
    return str;
    
}


-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(nonnull UITouch *)touch
{
    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {//如果当前是tableView
        //做自己想做的事
        return NO;
    }
    return YES;
}

-(void)SelectPayCardtapGesturedDetected:(UIGestureRecognizer *)tap
{
    CGPoint point = [tap locationInView:self.selectPayCardDetailView];
    
    if (point.y < ETScreenH - 400) {
        self.selectPayCardDetailView.backgroundColor = [UIColor clearColor];
        __weak SelectPayCardDetailView *weakSelf = self.selectPayCardDetailView;
        [UIView animateWithDuration:0.5 animations:^{
            weakSelf.frame = CGRectMake(0, ETScreenH, ETScreenW, ETScreenH);
        } completion:^(BOOL finished) {
            
        }];
    }
}


-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (tableView == self.selectPayCardDetailView.payCardTableView) {
        
        SelectCardTabFooterView *view = [[SelectCardTabFooterView alloc] init];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
        [view addGestureRecognizer:tap];
        view.backgroundColor = [UIColor whiteColor];
        return view;
        
    }else
    {
        return nil;
    }
}
-(void)tapAction
{
    NSLog(@"点击添加信用卡");
    [self PayDetailCardViewdismiss];
    AddCreditCardViewController *addCreditVC = [[AddCreditCardViewController alloc] init];
    
    //接收到添加信用卡页面回传过来的ID
    __weak __typeof(self)weakSelf = self;
   addCreditVC.returnValueBlock = ^(NSString * _Nonnull bankId, NSString * _Nonnull banName, NSString * _Nonnull bankPhone, NSString * _Nonnull bankCard, NSString * _Nonnull bankCode) {
        //赋值bankId
        self.bankId = bankId;
        self.bankCode = bankCode;
        NSLog(@"获取到bankID:%@",bankId);
        //自动根据ID去查询费率和通道
        [weakSelf getRateAndArriveTimeWith:bankId banName:banName leftPhone:bankPhone cardNum:bankCard];
        
    };
    
    [self.navigationController pushViewController:addCreditVC animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.sv.tableView) {
        return 44.4;
    }else
    {
        return 54;
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (tableView == self.selectPayCardDetailView.payCardTableView) {
        return 60;

    }else
    {
        return 0.01f;
    }
    
    
}
-(void)createNextStype
{
    self.nextStypeBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.nextStypeBtn.backgroundColor = [UIColor colorWithRed:91 / 255.0 green:113 / 255.0 blue:255 / 255.9 alpha:1];
    [self.nextStypeBtn setTitle:@"下一步" forState:(UIControlStateNormal)];
    [self.nextStypeBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    self.nextStypeBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    self.nextStypeBtn.frame = CGRectMake(0, self.view.frame.size.height - ETTopHeight - ETTabBarArcHeight - 44, self.view.frame.size.width, 44);
    [self.view addSubview:self.nextStypeBtn];
    [self.nextStypeBtn addTarget:self action:@selector(nextStypeBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
}
-(void)nextStypeBtnAction
{
    NSLog(@"点击下一步");
    //判断是否已经选择了付款卡
    if (self.bankNameTF.text.length == 0) {
        [self selectcardBtnAction];
        return;
    }
    //是否支持该银行
    NSDictionary *dic = @{@"bankCode":self.bankCode}.mutableCopy;
    NSString *url = [[ServerAddressModel shareInstance] fullTAnd0AddrWithParameter:@"/epay_apps/bankCard/searchBankListB0700"];
    [self showProgressTips:@"加载中" animated:YES];
    [[ETONEHttpClient sharedInstance] doHTTPSPOSTNOTips:url Parameters:dic HttpBody:nil SuccessHandler:^(id responseObject) {
        
        
        NSDictionary *dic = [responseObject mj_JSONObject];
        NSString *code = dic[@"code"];
        if ([@"0000" isEqualToString:code]) {
            [self getH5Url];
        }else
        {
            [self hideProgressTips:YES];
            [self showFailedResultTips:dic[@"msg"] animated:YES forSeconds:FAIL_SHOW_TIME_DEF];
        }
        
    } FailedHandler:^(NSError *error) {
        
        [self hideProgressTips:YES];
        [self showFailedResultTips:dic[@"msg"] animated:YES forSeconds:FAIL_SHOW_TIME_DEF];
        
    }];
    
}

//获取套现H5URL
-(void)getH5Url
{
    CreateNewOrderRequest *request = [[CreateNewOrderRequest alloc] init];
    request.transAmount = self.moneyStr;
    request.Id = self.bankId;
    request.payId = @"3";
    NSDictionary *dic = [request mj_keyValues];
    NSString *url = [[ServerAddressModel shareInstance] fullTAnd0AddrWithParameter:@"/epay_apps/payNew/payB0400"];
    [[ETONEHttpClient sharedInstance] doHTTPSPOSTNOTips:url Parameters:dic HttpBody:nil SuccessHandler:^(id responseObject) {
        
        
        [self hideProgressTips:YES];
        NSDictionary *dic = [responseObject mj_JSONObject];
        NSString *code = dic[@"code"];
        if ([@"0000" isEqualToString:code]) {
            [self dealCreateNewOrder:responseObject];
        }else
        {
            [self hideProgressTips:YES];
            [self showFailedResultTips:dic[@"msg"] animated:YES forSeconds:FAIL_SHOW_TIME_DEF];
        }
        
    } FailedHandler:^(NSError *error) {
        
        [self hideProgressTips:YES];
        [self showFailedResultTips:dic[@"msg"] animated:YES forSeconds:FAIL_SHOW_TIME_DEF];
        
    }];
}

-(void)dealCreateNewOrder:(id)responseObject
{
    CreateNewOrderResponse *createNewOrderResponse = [CreateNewOrderResponse mj_objectWithKeyValues:responseObject];
    NSString *urlStr = createNewOrderResponse.response.payUrl;
    if (urlStr.length == 0) {
        VerifyCardViewController *verifyVC = [[VerifyCardViewController alloc] init];
        [self.navigationController pushViewController:verifyVC animated:YES];
    }else
    {
        H5TradeViewController *tradeVC = [[H5TradeViewController alloc] init];
        tradeVC.urlStr = urlStr;
        [self.navigationController pushViewController:tradeVC animated:YES];
    }
    
    
}

-(void)PayDetailCardViewdismiss
{
    self.selectPayCardDetailView.backgroundColor = [UIColor clearColor];
    __weak SelectPayCardDetailView *weakSelf = self.selectPayCardDetailView;
    [UIView animateWithDuration:0.5 animations:^{
        weakSelf.frame = CGRectMake(0, ETScreenH, ETScreenW, ETScreenH);
    } completion:^(BOOL finished) {
        
    }];
}

-(void)textFieldDone
{
    [self.view endEditing:YES];
}

-(void)dealloc
{
    [self.selectPayCardDetailView removeFromSuperview];
}

@end
